#!/usr/bin/env python
import sys
from optparse import OptionParser
from stdeb.downloader import myprint, get_source_tarball


def main():
    usage = '%prog PACKAGE_NAME [options]'
    parser = OptionParser(usage)
    parser.add_option('--verbose', type='int',
                      help='verbosity level',
                      default=0)
    parser.add_option('--release', type='str',
                      help='specify a particular release',
                      default=None)
    parser.add_option('--allow-unsafe-download', action='store_true',
                      default=False,
                      help='allow unsafe downloads')
    (options, args) = parser.parse_args()
    if len(args) != 1:
        myprint('need exactly one PACKAGE_NAME', file=sys.stderr)
        parser.print_help()
        sys.exit(1)

    package_name = args[0]

    tarball_fname = get_source_tarball(
        package_name, verbose=options.verbose,
        release=options.release,
        allow_unsafe_download=options.allow_unsafe_download)
    myprint('OK: %s' % tarball_fname)


if __name__ == '__main__':
    main()
